#pragma once

#include <QWidget>
#include <QHBoxLayout>

class DockingSplitter;
class TabSidebar;
class DockingTabStack;
class TabManager;

/**
 * DockingArea - 停靠区域主容器
 * 管理整个停靠区域：左侧边栏 + 中央分割器 + 右侧边栏
 * 类似UE4编辑器的主界面布局
 */
class DockingArea : public QWidget {
    Q_OBJECT
    
public:
    explicit DockingArea(QWidget* parent = nullptr);
    explicit DockingArea(TabManager* tabManager, QWidget* parent = nullptr);
    ~DockingArea();
    
    // === 核心组件访问 ===
    DockingSplitter* rootSplitter() const { return m_rootSplitter; }
    TabSidebar* leftSidebar() const { return m_leftSidebar; }
    TabSidebar* rightSidebar() const { return m_rightSidebar; }
    TabManager* tabManager() const { return m_tabManager; }
    
    // === 布局管理 ===
    void setTabManager(TabManager* manager);
    void resetToDefaultLayout();
    void createUE4LikeLayout(); // 创建类似UE4的默认布局

    // === 侧边栏管理 ===
    void showLeftSidebar(bool show = true);
    void showRightSidebar(bool show = true);
    bool isLeftSidebarVisible() const;
    bool isRightSidebarVisible() const;
    
    // === 查找功能 ===
    DockingTabStack* findTabStackContaining(QWidget* content) const;
    QList<DockingTabStack*> getAllTabStacks() const;

signals:
    void layoutChanged();
    void sidebarVisibilityChanged(bool leftVisible, bool rightVisible);

protected:
    // === Qt事件重写 ===
    void resizeEvent(QResizeEvent* event) override;
    void showEvent(QShowEvent* event) override;

private slots:
    void onRootSplitterBecameEmpty();

private:
    // === 初始化 ===
    void setupDockingArea();
    void setupLayout();
    void setupConnections();
    void setupDefaultContent();

private:
    TabManager* m_tabManager;
    
    // === 布局组件 ===
    QHBoxLayout* m_mainLayout;
    TabSidebar* m_leftSidebar;
    DockingSplitter* m_rootSplitter;
    TabSidebar* m_rightSidebar;
    
    // === 状态 ===
    bool m_leftSidebarVisible;
    bool m_rightSidebarVisible;
    bool m_isResetting;
    bool m_layoutInitialized;
};

